﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Runtime.InteropServices;

namespace FlowCard
{
    public partial class Print : Form
    {
        [DllImport("winspool.drv")]
        public static extern bool SetDefaultPrinter(String Name);
        string content; int type;
        public Print(int type, string content)
        {
            this.type = type;
            this.content = content;
            InitializeComponent();
            initprintercombobox();
            loadTemplate();
        }
        //init load template of Crystal Report

        public void loadTemplate() {            
            //if (type == 0) {
            //    if (content=="宇航级-片式MLCC生产流转卡")
            //    {
            //        Cards.HKB7302 var = new Cards.HKB7302();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content=="宇航级-引线MLCC生产流转卡")
            //    {
            //        Cards.HKB7304 var = new Cards.HKB7304();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "国军标-MLCC生产流转卡")
            //    {
            //        Cards.HKB7306 var = new Cards.HKB7306();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "国军标-引线MLCC生产流转卡")
            //    {
            //        Cards.HKB7307 var = new Cards.HKB7307();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "MLCC生产流转卡")
            //    {
            //        Cards.HKB7310 var = new Cards.HKB7310();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //}
            //if (type == 1)
            //{
            //    if (content == "宇航级-片式MLCC生产流转卡")
            //    {
            //        Cards.HKB7303 var = new Cards.HKB7303();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "宇航级-引线MLCC生产流转卡")
            //    {
            //        Cards.HKB7305 var = new Cards.HKB7305();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "国军标-片式MLCC生产流转卡")
            //    {
            //        Cards.HKB7308 var = new Cards.HKB7308();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "国军标-引线MLCC生产流转卡")
            //    {
            //        Cards.HKB7309 var = new Cards.HKB7309();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "片式MLCC生产流转卡")
            //    {
            //        Cards.HKB7311 var = new Cards.HKB7311();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //    else if (content == "引线MLCC生产流转卡")
            //    {
            //        Cards.HKB7312 var = new Cards.HKB7312();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //}
            //if (type == 2)
            //{
            //    if (content == "引线MLCC生产流转卡")
            //    {
            //        Cards.HKB7313 var = new Cards.HKB7313();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //}
            //if (type == 3)
            //{
            //    if (content == "浆料配制/流延-生产流转卡")
            //    {
            //        Cards.HKB7301 var = new Cards.HKB7301();
            //        crystalReportViewer1.ReportSource = var;
            //    }
            //}
        }

        //Let the selected printer as the default printer
        private void button1_Click(object sender, EventArgs e)
        {
            if(printercombobox.SelectedItem != null)
            {
                SetDefaultPrinter(printercombobox.SelectedItem.ToString());
                MessageBox.Show(printercombobox.SelectedItem.ToString() + "已设置为默认打印机！"); 
            }
        }
        //Load System Printers which is setuped in computer
        private void initprintercombobox()
        {
            //new printDocument Object 
            PrintDocument printDocument = new PrintDocument();
            //Default Printer Name
            string var = printDocument.PrinterSettings.PrinterName;
            //load installed printers to combobox control;
            printercombobox.Items.Add(var);
            
            foreach (string  item in PrinterSettings.InstalledPrinters)
            {
                if (!item.Contains(var)) {
                    printercombobox.Items.Add(item);
                }
            }
            printercombobox.SelectedIndex = 0;
        }

        private void Print_Load(object sender, EventArgs e)
        {

        }
    }
}
